//
//  FSWForgetPwdEditController.m
//  voicetip_ios
//
//  Created by 伏圣文 on 2020/2/15.
//  Copyright © 2020 fusw. All rights reserved.
//

#import "FSWForgetPwdEditController.h"
#import "UIButton+Gradient.h"
@interface FSWForgetPwdEditController ()
@property (weak, nonatomic) IBOutlet UITextField *pwdText;
@property (weak, nonatomic) IBOutlet UILabel *pwdLabel;
@property (weak, nonatomic) IBOutlet UITextField *configPwdText;
@property (weak, nonatomic) IBOutlet UILabel *configPwdLabel;

@end

@implementation FSWForgetPwdEditController
- (IBAction)submitButton:(id)sender {
    NSDictionary *dict = @{@"mobile": self.mobile ,@"code":self.code ,@"newPassword": self.pwdText.text,@"checkPassword": self.configPwdText.text};
    [LoginNetRequest forgetPwdDataRequest:dict andBlock:^(id responseObject) {
        [FSWToast showWithText:@"密码修改成功"];
       for (UIViewController* viewcontroller in self.navigationController.viewControllers) {
            if ([viewcontroller isKindOfClass:NSClassFromString(@"FSWAllWKWebViewController")]) {
                [self popToViewController:viewcontroller];
                return ;
            }
        }
    } andFailBlock:^(NSString *error) {
        [FSWToast showWithText:error];
    }];
//    17854969635
    
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"忘记密码";
    //      [self.submitButtn setBackgroundColor:XCMainColor];
    
    [self.submitButtn gradientButtonWithSize:CGSizeMake(self.submitButtn.xc_width, self.submitButtn.xc_height) colorArray:@[(id)FSWNavEndColor,(id)FSWNavStartColor] percentageArray:@[@(0.0),@(1)] gradientType:GradientFromLeftToRight];
    @weakify(self);
    [[self.pwdText rac_textSignal] subscribeNext:^(NSString* x) {
        @strongify(self)
        if (self.pwdText.text.length > 0) {
            self.pwdLabel.hidden = YES;
        }else{
            self.pwdLabel.hidden = NO;
        }
    }];

    [[self.configPwdText rac_textSignal] subscribeNext:^(NSString* x) {
        @strongify(self)
        if (self.configPwdText.text.length > 0) {
            self.configPwdLabel.hidden = YES;
        }else{
            self.configPwdLabel.hidden = NO;
        }
    }];

    [[RACSignal combineLatest:@[self.pwdText.rac_textSignal,
                                self.configPwdText.rac_textSignal]
                       reduce:^(NSString* pwd, NSString *config_pwd){
        return @(pwd.length >= 6&& config_pwd.length >=6 && [config_pwd isEqualToString:pwd]);
    }]
     subscribeNext:^(id x) {
        if ([x boolValue]) {
            self.submitButtn.enabled = YES;
            self.submitButtn.backgroundColor = XCMainColor;
        }else{
            self.submitButtn.enabled = NO;
            self.submitButtn.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.2];
        }
    }];
}


@end
